package com.atguigu.gmall.common.config.minio;

import io.minio.MinioClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MinioAutoConfiguration {
    @Autowired
    MinioProperties minioProperties;

    @Bean
    public MinioClient minioClient() throws Exception {
        //1.创建minioClient
        MinioClient client = new MinioClient(minioProperties.getEndpoint(),minioProperties.getAccessKey(),minioProperties.getSecretKey());

        //2.判断桶是否存在
        boolean mall = client.bucketExists(minioProperties.getBucketName());
        if(!mall){
            client.makeBucket(minioProperties.getBucketName());
        }

        return  client;
    }
}
